package Mytest;

import javax.swing.*;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;

public class UseService  {
    public static List<Socket> socketList=new ArrayList<>();
    public static void main(String[] args) {
        UseService useService =new UseService();
        useService.start();
    }

    public void start(){
        try {
            ServerSocket serverSocket=new ServerSocket(9999);
            System.out.println("服务器已启动");
            while(true){

                Socket socket=serverSocket.accept();
                socketList.add(socket);
                System.out.println("有客户端连接上了"+socket.getInetAddress());
                System.out.println("连接客户端的数量"+socketList.size());
                //启动线程
                new Thread(new MessageThread(socket)).start();
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
